package com.bdqn.qnnews.schedule.controller;

import com.bdqn.qnnews.schedule.api.dto.TaskDto;
import com.bdqn.qnnews.schedule.service.TaskService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 定时任务的控制器类
 * @author xlzhang
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/task")
public class TaskController {

    private final TaskService taskService;

    /**
     * 添加延迟队列任务
     */
    @PostMapping("/add")
    public Long addTask(@RequestBody TaskDto task){
        return taskService.addTask(task);
    }

    /**
     * 消费任务
     */
    @PostMapping("/poll/{taskTopic}")
    public List<TaskDto> pollTask(@PathVariable(value = "taskTopic") Integer taskTopic){
        return taskService.pollTask(taskTopic);
    }
}